package org.nlp2rdf.navigator.benchmark.cli;

import com.hp.hpl.jena.rdf.model.Resource;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.nlp2rdf.navigator.benchmark.BenchmarkContext;
import org.nlp2rdf.navigator.benchmark.BenchmarkUtils;
import org.nlp2rdf.navigator.benchmark.PoolUtils;
import org.nlp2rdf.navigator.benchmark.Sample;
import org.springframework.context.ApplicationContext;

import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;

/**
 * Created by Claus Stadler
 * Date: Oct 23, 2010
 * Time: 10:28:01 AM
 */
public class RunPoolRandom {

    private static Options cliOptions = new Options()
        .addOption("f", "sampleFile", true, "File containing a list of positive samples (negatives will be ignored)")
        .addOption("c", "configFile", true, "Spring XML config")
        .addOption("r", "randomSeed", true, "Random seed")
        .addOption("s", "poolSize", true, "Size of the pool");

    public static void main(String[] args)
            throws Exception
    {
        CommandLine commandLine = CliUtils.getGnuCommandLine(cliOptions, args);
        ApplicationContext context = CliUtils.getApplicationContext(commandLine, commandLine.getOptionValue("c"));

        BenchmarkContext con = new BenchmarkContext(context);

        Integer size = Integer.parseInt(commandLine.getOptionValue("s"));
        Random random = CliUtils.getRandom(commandLine.getOptionValue("r"));

        List<Resource> resources = BenchmarkUtils.readResources(commandLine.getOptionValue("f"));
        Set<Resource> positives = new HashSet<Resource>(resources);
        //logger.info("Resources = " + positives);

        Sample<Resource> sample = PoolUtils.generateRandomSearchPool(con.getSparqlEndpoint(), con.getGraphNames(), positives, size, random);

        CliUtils.outputSample(sample);
    }
}
